<html>
  <head>
    <title>Earl Of March News Feed</title>
	<link rel="stylesheet" type="text/css" href="css/Default.css" />
  </head>
  <body text="#bfae20" bgcolor="2d5306" style="font-size:24px;font-family:Baskerville Old Face;">
    <div id="tickerContainer">
      <dl id="ticker">
		<!-- set these contents with javascript -->
      </dl>
    </div>
	<script type="text/javascript" src="data/newsfeed_data.js"></script>
    <script type="text/javascript" src="exec/jquery.js"></script>
	<script type="text/javascript" src="data/reload.js"></script>
    <script type="text/javascript">
	
	setTimeout("location.reload(true);",reload_time+1000); //To run it once after reload time and a second
	//*
	
	//Sort items array here:
	
	var tempArray = new Array(); //Array of 4-digit date values used to compare dates
	var tempMonth;
	
	
	for(var i=0; i<items.length; i++) //Calculates the 4-digit date value for each newsfeed
	{
		tempMonth = (getMonthValue((items[i].substring(0, items[i].indexOf(" "))))); 
		tempMonth = (tempMonth + 3)%12;
		tempArray[i] = (tempMonth*100 +	((items[i].substring(items[i].indexOf(" ") + 1, items[i].indexOf(":") - 2))-0));
	}	
	
	//Sorting the newsfeeds:	
	for(var i = 0; i < items.length; i++) //COULD BE FASTER/MORE EFFICIENT. We could change sort type some time in the future.
	{
		for(var j = items.length; j >= 0; j--)
		{
			if(tempArray[j] >= tempArray[j+1]) //Compares 4-digit date value
			{
				var temp = tempArray[j+1];
				tempArray[j+1] = tempArray[j];
				tempArray[j] = temp;
				
				temp = items[j+1];
				items[j+1] = items[j];
				items[j] = temp;
			}
			
		}
	}	
	
	tempArray = null; //Empties array
	
	for(var i=0; i<items.length; i++) //Ensures it has proper format
	{
		var arr = items[i].split(':');
		if(arr.length > 1)
		{
			var add = '<dt class=\"heading\"><br><b>'+arr[0]+'</b></dt><dd class=\"text\">';
			for(var j=1; j<arr.length; j++)
			{
				add += arr[j] + ":" ;
			}
			add = add.substring(0, add.length - 1) + '</dd>';
			document.getElementById("ticker").innerHTML += (add);
		}//If the length isn't longer then 1, it isn't formated right. So don't display.
	}
	//*/
	
	function getMonthValue(str) //Calculates the month value of each month
	{
		var months_array = new Array ('Jan','Feb','March','April','May','June','July','Aug','Sept','Oct','Nov','Dec');
		
		for(var i = 0; i < months_array.length; i++)
		{
			if(str == months_array[i]){
			return i + 1;
			}
			
		}
	}

	//code below was not created by the previous ICS4U workers on this project. Don't touch.
	  $(function() {
	  
		//cache the ticker
		var ticker = $("#ticker");
		  
		//wrap dt:dd pairs in divs
		ticker.children().filter("dt").each(function() {
		  
		  var dt = $(this),
		    container = $("<div>");
		  
		  dt.next().appendTo(container);//adds title
		  dt.prependTo(container);//puts the text in properly
		  
		  container.appendTo(ticker);
		});
				
		//hide the scrollbar
		ticker.css("overflow", "hidden");
		
		//animator function
		function animator(currentItem) {
		    
		  //work out new anim duration
		  var distance = currentItem.height();//change to width for side scrolling?
			duration = (distance + parseInt(currentItem.css("marginTop"))) / 0.025;//change to marginLeft SS?

		  //animate the first child of the ticker
		  currentItem.animate({ marginTop: -distance }, duration, "linear", function() {//margin left SS?
		    
			//move current item to the bottom
			currentItem.appendTo(currentItem.parent()).css("marginTop", 0);//marginleft ss?

			//recurse
			animator(currentItem.parent().children(":first"));
		  }); 
		};
		
		//start the ticker
		animator(ticker.children(":first"));
				
		
	  });
	  
	  
    </script>
  </body>
</html>
